﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.ComponentModel.Composition;
using System.ComponentModel.Composition.Hosting;

namespace SimpleCalculator
{
    class Program
    {
        private CompositionContainer _container;
        [Import(typeof(ICalculator))]
        public ICalculator calculator;

        static void Main(string[] args)
        {
            Program p = new Program();
            string s;
            Console.WriteLine("Enter Command : ");
            while (true)
            {
                s = Console.ReadLine();
                Console.WriteLine(p.calculator.Calculate(s));
            }
        }

        private Program(){
            var catalog = new AggregateCatalog();

            catalog.Catalogs.Add(new AssemblyCatalog(typeof(Program).Assembly));
            catalog.Catalogs.Add(new DirectoryCatalog(@"I:\ProjetsPerso\SimpleCalculator_MEF_Sample\Extensions\ExternalOperators\bin\Debug"));

            _container = new CompositionContainer(catalog);

            try { this._container.ComposeParts(this); }
            catch(CompositionException compositionException){ Console.WriteLine(compositionException.ToString()); }
        }
    }
}
